package com.android.SchoolManagerSystem;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

public class PageManager
{
	final public static int PAGE_LOGIN = 0;
	final public static int PAGE_OPERATELIST = 1;
	final public static int PAGE_MYCENTER = 2;
	final public static int PAGE_SCOREQUERY = 3;
	final public static int PAGE_ONLINECOURSE = 4;
	final public static int PAGE_PRACTIVE = 5;
	final public static int PAGE_JOBINFO = 6;
	final public static int PAGE_STATIONMAIL = 7;
	final public static int PAGE_NUMBER_MAX = 8;

	private static ViewGroup mRootView = null;
	final private static int PAGE_ROOT = PAGE_OPERATELIST;
	private static int mCurrentPage = PAGE_LOGIN;    
	
	public static void setRootView(ViewGroup rootView)
	{
		mRootView = rootView;
	}
	
	public static void changeToRootPage()
	{
		changeToPage(PAGE_ROOT);
	}
	
	public static boolean isRootPage()
	{
		return mCurrentPage == PAGE_ROOT ? true : false;
	}
	

    public static void changeToPage(int newPage)
    {
    	int nResID = getPageResID(newPage);
    	if (nResID != 0)
    	{
    		hideCurrentPage();
    		View page = mRootView.findViewById(nResID);
    		page.setVisibility(View.VISIBLE);
    		
    		mCurrentPage = newPage;
    	}
    }
    
    private static int getPageResID(int page)
    {
    	int nResID = 0;
    	
    	switch (page)
    	{
	    	case PAGE_OPERATELIST:
			{
				nResID = R.id.operaterlist;
			}
			break;
			
	    	case PAGE_MYCENTER:
			{
				nResID = R.id.mycenter;
			}
			break;
			
	    	case PAGE_SCOREQUERY:
			{
				nResID = R.id.scorequery;
			}
			break;
			
	    	case PAGE_ONLINECOURSE:
			{
				nResID = R.id.onlinecourse;
			}
			break;
	    	case PAGE_LOGIN:
	    	{
	    		nResID = R.id.loginpage;
	    	}
	    	break;
    	}
    	
    	return nResID;
    }
    
    private static void hideCurrentPage()
    {
    	if (mCurrentPage == PAGE_ROOT)
    	{
    		return;
    	}
    	
    	int nResID = getPageResID(mCurrentPage);
    	if (nResID != 0)
    	{
    		View page = mRootView.findViewById(nResID);
        	page.setVisibility(View.INVISIBLE);
    	}
    }
}